home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / source.exe / POSIX / SH / STD / STDC / STRCMP.C < prev    next >
C/C++ Source or Header  |  1992-07-13  |  758b  |  41 lines

  1. #include <string.h>
  2.  
  3. /* Modified by Eric Gisin */
  4.  
  5. /*
  6.  * strcmp - compare string s1 to s2
  7.  */
  8.  
  9. int                /* <0 for <, 0 for ==, >0 for > */
  10. strcmp(s1, s2)
  11. Const char *s1;
  12. Const char *s2;
  13. {
  14.     register Const char *scan1;
  15.     register Const char *scan2;
  16. #if 0                /* some machines prefer int to char */
  17.     register int c1, c2;
  18. #else
  19.     register char c1, c2;
  20. #endif
  21.  
  22.     scan1 = s1;
  23.     scan2 = s2;
  24.     while ((c1 = *scan1++) == (c2 = *scan2++) && c1 != 0)
  25.         ;
  26.  
  27.     /*
  28.      * The following case analysis is necessary so that characters
  29.      * which look negative collate low against normal characters but
  30.      * high against the end-of-string NUL.
  31.      */
  32.     if (c1 == '\0' && c2 == '\0')
  33.         return(0);
  34.     else if (c1 == '\0')
  35.         return(-1);
  36.     else if (c2 == '\0')
  37.         return(1);
  38.     else
  39.         return(c1 - c2);
  40. }
  41.